/*
 * @Descripttion:
 * @version:
 * @Author: lwj
 * @Date: 2022-05-26 13:54:03
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2022-12-20 16:41:29
 */

import {
    reqSpaceManager,
    reqOrgList,
} from "@/api/api";
export default {
    data() {
        return {
            isolateStatusArr: [{
                    value: "2",
                    label: "隔离中",
                },
                // {
                //     value: "1",
                //     label: "待隔离",
                // },
                {
                    value: "3",
                    label: "解除隔离",
                },
            ],
            isolationTypeArr: [{
                    value: "1",
                    label: "居家隔离",
                }, {
                    value: "2",
                    label: "酒店隔离",
                },
                {
                    value: "3",
                    label: "定点医院隔离",
                }, {
                    value: "4",
                    label: "其他隔离",
                },
            ],
            orgList: [],
            buildList: [],
            floorList: [],
            spaceList: [],
            loadingReset: false,
            loadingSearch1: false,
            flag: true,
            loading: false,
            sysInstanceIndex: 1,
            sysInstanceTotalPages: 10,
            sysInstanceIndex2: 1,
            sysInstanceTotalPages2: 10,
            loading2: false,
            sysInstanceIndex3: 1,
            sysInstanceTotalPages3: 10,
            loading3: false,
            sysInstanceIndex4: 1,
            sysInstanceTotalPages4: 10,
            loading4: false,
        }
    },
    mounted() {},
    methods: {
        async loadMore() {
            if (this.sysInstanceIndex >= Math.ceil(this.sysInstanceTotalPages / 10)) return
            this.sysInstanceIndex++;
            this.loading = true;
            // 获取列表数据的方法
            await this.getOrgList()
            this.loading = false;
        },
        // 下拉请求列表
        enterpriseChange(val) {
            if (val && this.flag) {
                this.getOrgList();
                this.flag = false; //只执行一次
            }
        },
        // 获取单位列表
        async getOrgList() {
            let res = await reqOrgList({
                tenantId: this.user.tenantId,
                userId: this.user.userId,
                roleName: this.user.roleName,
            });
            if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
            this.orgList = res.data.rows
        },
        changeOrgId() {
            this.sysInstanceIndex2 = 1
            this.sysInstanceTotalPages2 = 10
            this.sysInstanceIndex3 = 1
            this.sysInstanceTotalPages3 = 10
            this.sysInstanceIndex4 = 1
            this.sysInstanceTotalPages4 = 10
            this.buildList = []
            this.floorList = []
            this.spaceList = [];
            this.searchForm.buildId = "";
            this.searchForm.floorId = "";
            this.searchForm.spaceId = "";
            this.getBuildList();
        },


        async loadMore2() {
            if (this.sysInstanceIndex2 >= Math.ceil(this.sysInstanceTotalPages2 / 10)) return
            this.sysInstanceIndex2++;
            this.loading2 = true;
            // 获取列表数据的方法
            await this.getBuildList()
            this.loading2 = false;
        },
        // 获取建筑物列表
        async getBuildList() {
            let res = await reqSpaceManager(this.sysInstanceIndex2, 10, {
                userId: this.user.userId,
                roleName: this.user.roleName,
                orgId: this.searchForm.orgId,
                metaCode: 1,
                isStatistics: 0
            });
            if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
            this.sysInstanceTotalPages2 = res.data.total
            this.buildList = [...this.buildList, ...res.data.rows]
        },
        // 选择建筑物
        changeBuild() {
            this.sysInstanceIndex3 = 1
            this.sysInstanceTotalPages3 = 10
            this.sysInstanceIndex4 = 1
            this.sysInstanceTotalPages4 = 10
            this.floorList = this.spaceList = [];
            this.searchForm.floorId = this.searchForm.spaceId = "";
            this.getFloorList();
        },

        async loadMore3() {
            if (this.sysInstanceIndex3 >= Math.ceil(this.sysInstanceTotalPages3 / 10)) return
            this.sysInstanceIndex3++;
            this.loading3 = true;
            // 获取列表数据的方法
            await this.getFloorList()
            this.loading3 = false;
        },
        // 获取楼层列表
        async getFloorList() {
            let res = await reqSpaceManager(this.sysInstanceIndex3, 10, {
                userId: this.user.userId,
                roleName: this.user.roleName,
                orgId: this.searchForm.orgId,
                parentId: this.searchForm.buildId,
                metaCode: 2,
                isStatistics: 0
            });
            if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
            this.sysInstanceTotalPages3 = res.data.total
            this.floorList = [...this.floorList, ...res.data.rows]
        },
        // 选择楼层
        changeFloor() {
            this.sysInstanceIndex4 = 1
            this.sysInstanceTotalPages4 = 10
            this.spaceList = [];
            this.searchForm.spaceId = "";
            this.getSpaceList();
        },

        async loadMore4() {
            if (this.sysInstanceIndex4 >= Math.ceil(this.sysInstanceTotalPages4 / 10)) return
            this.sysInstanceIndex4++;
            this.loading4 = true;
            // 获取列表数据的方法
            await this.getSpaceList()
            this.loading4 = false;
        },
        // 获取安装点列表
        async getSpaceList() {
            let res = await reqSpaceManager(this.sysInstanceIndex4, 10, {
                userId: this.user.userId,
                roleName: this.user.roleName,
                orgId: this.searchForm.orgId,
                parentId: this.searchForm.floorId,
                metaCode: 3,
                isStatistics: 0
            });
            if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
            this.sysInstanceTotalPages4 = res.data.total
            this.spaceList = [...this.spaceList, ...res.data.rows]
        },
        // 搜索
        async searchClick1() {
            this.page = 1;
            this.limit = 10;
            this.loadingSearch1 = true;
            await this.getDataList();
            this.loadingSearch1 = false;
        },
        // 高级搜索重置
        async resetClick() {
            this.page = 1;
            this.limit = 10;
            this.searchForm.orgId =
                this.searchForm.parkId =
                this.searchForm.buildId =
                this.searchForm.floorId =
                this.searchForm.spaceId =
                this.searchForm.isolationType =
                "";
            this.searchForm.isolationStatus = "2";
            this.loadingReset = true;
            await this.getDataList();
            this.loadingReset = false;
        },
    },
};